package cn.itcast.interceptor;

import cn.itcast.domain.StringToUrl;
import cn.itcast.domain.Student;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class LoginInterceptor implements HandlerInterceptor {

//    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object o) throws Exception {
//        String url = request.getRequestURI();
//        System.out.println(url);
//        HttpSession session = request.getSession();
//        Student student = (Student) session.getAttribute("student");
//        if(student != null){
//            return true;
//        }
//        request.setAttribute("msg", "您还没有登录，请先登录！");
//        request.getRequestDispatcher("/index.html").forward(request, response);
//        return false;


//        String path = request.getRequestURI();
//        int i = -1;
//        String url[] = StringToUrl.url2();
//        HttpSession session = request.getSession();
//        Student student = (Student) session.getAttribute("student");
//        for (String urll : url){
//            if (urll.equals(path)){
//                i = 1;
//                break;
//            }else {
//                i = 0;
//            }
//        }
//
//        System.out.println("我是i"+i);
//
//        if ( i == 1){
//            return true;
//        }else if (student == null ){
//            return false;
//        }
//
//    }

    public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o) throws Exception {
        return false;
    }

    public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {

    }

    public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {

    }
}
